package org.example.chatservice.config;

import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.Consumer;
import org.springframework.kafka.listener.CommonErrorHandler;
import org.springframework.kafka.listener.MessageListenerContainer;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class KafkaErrorHandler implements CommonErrorHandler {
    
    @Override
    public void handleRecord(Exception thrownException, 
                           org.apache.kafka.clients.consumer.ConsumerRecord<?, ?> record,
                           Consumer<?, ?> consumer,
                           MessageListenerContainer container) {
        log.error("Error while processing Kafka record: {}", record, thrownException);
        // 实现自定义错误处理逻辑
        // 例如：将失败的消息保存到数据库或发送到死信主题
    }
}